package be.myandroid.games;

import android.util.Log;

public abstract class GameLevel {
	public static int currentLevel = 0;
	private static GameLevel instance;
	private static int MAX_LEVEL = 2;
	private boolean custom = false;
	//public int newCircles = 63;
	//public int remainingCircles = 5;
	public int newCircles = 10;
	public int remainingCircles = 8;
	public int MaxPushes = 1;
	public int ExplTime = 100;
	public float ExplSize = 0.4f;
	
	public GameLevel(int currentLevel){
		GameLevel.currentLevel = currentLevel;
		changeGameLevel(currentLevel);
		Log.d("GameLevel","Loaded level: " + currentLevel);
		instance = this;
	}
	
	public static GameLevel getInstance(){
		if(instance == null)
			(new Exception("GameLevel is not created")).printStackTrace();
		return instance;
	}
	public void setLevel(int newCircles, int remainingCircles, int maxPushes, int explTime, float explSize){
		this.custom = true;
		this.newCircles = newCircles;
		this.remainingCircles = remainingCircles;
		this.MaxPushes = maxPushes;
		this.ExplTime = explTime;
		this.ExplSize = explSize;
	}
	
	public void changeGameLevel(int level){
		if(level <= currentLevel)
			generateLevel(level);
		else {
			Log.d("GameLevel","Cannot give gameLevel " +level+ " which is higher than current level " + currentLevel);
			generateLevel(currentLevel);
		}
	}
	
	private void generateLevel(int level){
		this.custom = false;
		switch (level) {
		case 0:
			newCircles = 10;
			remainingCircles = 8;
			break;
		default:
			newCircles = 63;
			remainingCircles = 5;
			break;
		}
	}
	
	public abstract void storeProgress(int currentLevel);
	
	public void nextLevel(){
		if(currentLevel < 0 | currentLevel >= MAX_LEVEL)
			return;
		currentLevel++;
		generateLevel(currentLevel);
		storeProgress(currentLevel);
		return;
	}
}
